<?php
/*
 * @Author: 杨红兵 
 * @Date: 2022-07-13 16:44:30 
 * @Last Modified by: 杨红兵
 * @Last Modified time: 2022-07-13 16:45:23
 */

namespace app\libraries\utils\validate;

use app\Request;
use think\Service;

class VaildatesService extends Service
{
    public function register()
    {
        $this->app->resolving(function ($object, $app) {
            unset($app);
            if ($object instanceof Request && get_class($object) !== Request::class) {
                /**
                 * @var \think\Request
                 */
                $request = app('request');
                $object->withHeader($request->header())
                    ->withServer($request->server())
                    ->withInput($request->getInput())
                    ->withGet((array)$request->get())
                    ->withPost((array)$request->post())
                    ->withCookie((array)$request->cookie())
                    ->withFiles((array)$request->file())
                    ->setBaseUrl($request->server('request_uri'))
                    ->setUrl($request->server('request_uri') . (!empty($request->server('query_string')) ?
                        '?' . $request->server('query_string') : ''))
                    ->setPathinfo(ltrim($request->server('path_info'), '/'))
                    ->setDomain($request->domain())
                    ->setSubDomain($request->subDomain())
                    ->setPanDomain($request->panDomain())
                    ->setHost($request->host())
                    ->setUrl($request->url())
                    ->setRoot($request->root())
                    ->setController($request->controller())
                    ->setAction($request->action())
                    ->setMethod($request->method())
                    ->setRule($request->rule())
                    ->refreshProperty();
                $object->validateResolved();
            }
        });
    }
}
